﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Sector7.Restaurant.Modules.BIZZ.LocalService;
using Sector7.Restaurant.CoreType.Enums;
using Sector7.Restaurant.CoreType.Const;
using Sector7.Framework.Enums;

namespace Sector7.Restaurant.Modules.BIZZ.Controls
{
    /// <summary>
    /// TableControl.xaml 的交互逻辑
    /// </summary>
    public partial class TableControl : Border
    {
        private Brush _normalBrush = null;
        private Brush _focusedBursh = null;

        private RS_Table _table = null;

        public RS_Table Table
        {
            get { return _table; }
            set
            {
                _table = value;
                this.DataContext = _table;
                InitializeBackgroundBrush();
            }
        }

        public TableStatusType Status
        {
            get { return (TableStatusType)_table.Status; }
            set
            {
                _table.Status = (int)value;

                InitializeBackgroundBrush();

                this.Background = _normalBrush;
            }
        }

        public TableControl()
        {
            InitializeComponent();
        }

        public TableControl(RS_Table table)
        {
            InitializeComponent();

            this.Table = table;
        }

        public void InitializeBackgroundBrush()
        {
            Color normalColor, focusedColor;

            TableStatusType status = (TableStatusType)_table.Status;
            switch (status)
            {
                case TableStatusType.Idle:
                    normalColor = THEME_BLENDENT.TABLE_COLOR_IDLE;
                    break;
                case TableStatusType.Used:
                    normalColor = THEME_BLENDENT.TABLE_COLOR_USED;
                    break;
                case TableStatusType.Reserved:
                    normalColor = THEME_BLENDENT.TABLE_COLOR_RESERVED;
                    break;
                case TableStatusType.Disabled:
                    normalColor = THEME_BLENDENT.TABLE_COLOR_DISABLED;
                    break;
                default:
                    normalColor = THEME_BLENDENT.TABLE_COLOR_NONE;
                    break;
            }

            focusedColor = THEME_BLENDENT.TABLE_COLOR_FOCUSED;

            _normalBrush = new SolidColorBrush(normalColor);
            _focusedBursh = new SolidColorBrush(focusedColor);
        }

        private void Border_Loaded(object sender, RoutedEventArgs e)
        {
            InitializeBackgroundBrush();

            this.Background = _normalBrush;
        }

        private void Border_MouseEnter(object sender, MouseEventArgs e)
        {
            this.Background = _focusedBursh;
        }

        private void Border_MouseLeave(object sender, MouseEventArgs e)
        {
            this.Background = _normalBrush;
        }
    }
}
